package com.qf.controller.manager;

import com.github.pagehelper.PageInfo;
import com.qf.entitys.Evaluate;
import com.qf.entitys.RespBean;
import com.qf.service.EvaluateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/manager/evaluate")
public class ManagerEvaluateController {
    @Resource
    private EvaluateService service;

    @GetMapping("/list")
    public String list(Evaluate evaluate,Integer pageindex,HttpServletRequest request){
        PageInfo<Evaluate> evaluatePageInfo = service.selectList(evaluate, pageindex);
        request.setAttribute("pageInfo",evaluatePageInfo);
        return "manager/evaluatelist";
    }
    @GetMapping("/del")
    @ResponseBody
    public RespBean delById(Integer id){
        try {
            int i = service.deleteByPrimaryKey(id);
            if (i>0){
                return RespBean.success("删除成功");
            }else {
                return RespBean.error("删除失败");
            }
        }catch (Exception ex){
            return RespBean.error("删除失败");
        }
    }

    @GetMapping("/delbyids")
    @ResponseBody
    public RespBean delbyids(@RequestParam("ids[]")Integer[] ids){
        try {
            int i = service.deleteByIds(ids);
            if (i>0){
                return RespBean.success("批量删除成功！");
            }else {
                return RespBean.error("批量删除失败！");
            }
        }catch (Exception ex){
            return RespBean.error("批量删除失败！");
        }
    }

}
